package com.runtu.domain.trade.service.settlement.factory;

import com.runtu.domain.trade.model.entity.*;
import com.runtu.domain.trade.service.lock.factory.TradeLockRuleFilterFactory;
import com.runtu.domain.trade.service.lock.filter.ActivityUsabilityRuleFilter;
import com.runtu.domain.trade.service.lock.filter.UserTakeLimitRuleFilter;
import com.runtu.domain.trade.service.settlement.filter.EndRuleFilter;
import com.runtu.domain.trade.service.settlement.filter.OutTradeNoRuleFilter;
import com.runtu.domain.trade.service.settlement.filter.SCRuleFilter;
import com.runtu.domain.trade.service.settlement.filter.SettableRuleFilter;
import com.runtu.types.design.framework.link.model2.LinkArmory;
import com.runtu.types.design.framework.link.model2.chain.BusinessLinkedList;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * @ClassName TradeSettlementRuleFilterFactory
 * @Description 交易结算规则过滤工厂
 * @date 2025/8/19 23:11
 * @Version 1.0
 */
@Slf4j
@Service
public class TradeSettlementRuleFilterFactory {

    @Bean("tradeSettlementRuleFilter")
    public BusinessLinkedList<TradeSettlementRuleCommandEntity, TradeSettlementRuleFilterFactory.DynamicContext,
            TradeSettlementRuleFilterBackEntity> tradeSettlementRuleFilter(
            SCRuleFilter scRuleFilter,
            OutTradeNoRuleFilter outTradeNoRuleFilter,
            SettableRuleFilter settableRuleFilter,
            EndRuleFilter endRuleFilter) {

        // 组装链
        LinkArmory<TradeSettlementRuleCommandEntity, TradeSettlementRuleFilterFactory.DynamicContext, TradeSettlementRuleFilterBackEntity> linkArmory =
                new LinkArmory<>("交易结算规则过滤链", scRuleFilter, outTradeNoRuleFilter, settableRuleFilter, endRuleFilter);

        // 链对象
        return linkArmory.getLogicLink();

    }



    /**
     * 定义一个上下文 不好维护的信息 可以放到上下文中 可以一直串联
     * 方便我们随时到不同的结点去调用
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DynamicContext{
        // 订单营销实体对象
        private MarketPayOrderEntity marketPayOrderEntity;
        // 拼团组队实体对象
        private GroupBuyTeamEntity groupBuyTeamEntity;

    }

}
